<template>
	<view>
		<view class="nav">
			<view class="nav-one">
				<p>建仓时间:</p>
				<!-- <p>平仓时间：</p> -->
				<p>交易标的：</p>
				<p>开仓价格：</p>
				<!-- <p>平仓价格：</p> -->
				<p>手数：</p>
				<p>合约价值：</p>
				<p>盈亏</p>
				<p>手续费</p>
				<p>单号</p>
				<p>止盈比例：</p>
				<p>止盈价格：</p>
				<p>止损比例：</p>
				<p>止损价格：</p>
				<p>延期费：</p>
				<p>方向</p>
			</view>
			<view class="nav-two">
				<p>{{ JSON.parse(this.msg).create_date | timing }}</p>
				<!-- <p>{{ JSON.parse(this.msg).update_date | timing }}</p> -->
				<p>{{ JSON.parse(this.msg).trade_kind }}</p>
				<p>{{ JSON.parse(this.msg).open_price }}</p>
				<!-- <p>{{JSON.parse(this.msg).close_price}}</p> -->
				<p>{{ JSON.parse(this.msg).volumn }}</p>
				<p>{{ JSON.parse(this.msg).cost }}</p>

             <!-- <view v-if="JSONdate.trade_type == 'sel'">
              	<view v-if="JSONdate.trade_kind == 'BTCUSDT'">{{ ((JSONdate.open_price-JSONdate.close_price)* JSONdate.volumn * 10) | pointThree }}</view>
              	<view v-if="JSONdate.trade_kind == 'ETHUSDT'">{{ ((JSONdate.open_price-JSONdate.close_price)*JSONdate.volumn * 40) | pointThree }}</view>
              	<view v-if="JSONdate.trade_kind == 'LTCUSDT'">{{ ((JSONdate.open_price-JSONdate.close_price)*JSONdate.volumn * 50) | pointThree }}</view>
              	<view v-if="JSONdate.trade_kind == 'IFLUSDT'">{{ ((JSONdate.open_price-JSONdate.close_price)*JSONdate.volumn * 80) | pointThree }}</view>
              	<view v-if="JSONdate.trade_kind == 'ICLUSDT'">{{ ((JSONdate.open_price-JSONdate.close_price)*JSONdate.volumn * 80) | pointThree }}</view>
              </view> -->
                
				<view v-if="JSON.parse(this.msg).trade_type == 'buy'">
					<p v-if="JSON.parse(this.msg).trade_kind == 'BTCUSDT'">
						{{ (subFun(BTCUSDT, JSON.parse(this.msg).open_price) * JSON.parse(this.msg).volumn * 10) | pointThree }}
					</p>
					<p v-if="JSON.parse(this.msg).trade_kind == 'ETHUSDT'">
						{{ (subFun(ETHUSDT, JSON.parse(this.msg).open_price) * JSON.parse(this.msg).volumn * 40) | pointThree }}
					</p>
					<p v-if="JSON.parse(this.msg).trade_kind == 'LTCUSDT'">
						{{ (subFun(LTCUSDT, JSON.parse(this.msg).open_price) * JSON.parse(this.msg).volumn * 50) | pointThree }}
					</p>
					<p v-if="JSON.parse(this.msg).trade_kind == 'HS300'">
						{{ (subFun(HS300USDT, JSON.parse(this.msg).open_price) * JSON.parse(this.msg).volumn * 40) | pointThree }}
					</p>
					<p v-if="JSON.parse(this.msg).trade_kind == 'IC500'">
						{{ (subFun(IC500USDT, JSON.parse(this.msg).open_price) * JSON.parse(this.msg).volumn * 40) | pointThree }}
					</p>
				</view>
				<view v-if="JSON.parse(this.msg).trade_type == 'sel'">
					<p v-if="JSON.parse(this.msg).trade_kind == 'BTCUSDT'">
						{{ (subFun(JSON.parse(this.msg).open_price, BTCUSDT) * JSON.parse(this.msg).volumn * 10) | pointThree }}
					</p>
					<p v-if="JSON.parse(this.msg).trade_kind == 'ETHUSDT'">
						{{ (subFun(JSON.parse(this.msg).open_price, ETHUSDT) * JSON.parse(this.msg).volumn * 40) | pointThree }}
					</p>
					<p v-if="JSON.parse(this.msg).trade_kind == 'LTCUSDT'">
						{{ (subFun(JSON.parse(this.msg).open_price, LTCUSDT) * JSON.parse(this.msg).volumn * 50) | pointThree }}
					</p>
					<p v-if="JSON.parse(this.msg).trade_kind == 'HS300'">
						{{ (subFun(JSON.parse(this.msg).open_price, HS300USDT) * JSON.parse(this.msg).volumn * 40) | pointThree }}
					</p>
					<p v-if="JSON.parse(this.msg).trade_kind == 'IC500'">
						{{ (subFun(JSON.parse(this.msg).open_price, IC500USDT) * JSON.parse(this.msg).volumn * 40) | pointThree }}
					</p>
				</view>
				<p>{{ JSON.parse(this.msg).cost * 0.1 }}</p>
				<p>{{ JSON.parse(this.msg).receiptnum }}</p>
				<p>{{ JSON.parse(this.msg).stop_win * 100 }}%</p>
				<p>{{ JSON.parse(this.msg).stop_win_price }}</p>
				<p>{{ JSON.parse(this.msg).stop_loss * 100 }}%</p>
				<p>{{ JSON.parse(this.msg).stop_loss_price }}</p>
				<p>{{ JSON.parse(this.msg).storage_cost }}</p>
				<view v-if="JSON.parse(this.msg).trade_type == 'buy'">买入</view>
				<view v-if="JSON.parse(this.msg).trade_type == 'sel'">卖出</view>
			</view>
			
			
		</view>
		<!-- 点击平仓 -->
		<button @tap="tradeClose" style="width: 30%;margin-top: 30upx;" type="primary">平仓</button>
	</view>
</template>
<script>
import request from '@/utils/request';
import { mapState, mapGetters } from 'vuex';
import moment from 'moment';
import {toast} from '@/utils/toast'
export default {
	data() {
		return {
			msg: []
		};
	},
	filters: {
		timing(val) {
			return moment(val).format('YYYY-MM-DD HH:mm:ss');
		},
		pointThree(val) {
			return Number(val).toFixed(2);
		}
	},
	mounted() {
		console.log(this.msg, 555);
	},
	computed: {
		...mapState('user', ['BTCUSDT']),
		...mapState('user', ['ETHUSDT']),
		...mapState('user', ['LTCUSDT']),
		...mapState('user', ['HS300USDT']),
		...mapState('user', ['IC500USDT']),
		...mapState('user', ['userinfo']),
	},
	methods: {
		subFun(arg1, arg2) {
			var r1, r2, m, n;
			try {
				r1 = arg1.toString().split('.')[1].length;
			} catch (e) {
				r1 = 0;
			}
			try {
				r2 = arg2.toString().split('.')[1].length;
			} catch (e) {
				r2 = 0;
			}
			m = Math.pow(10, Math.max(r1, r2));
			n = r1 >= r2 ? r1 : r2;
			return ((arg1 * m - arg2 * m) / m).toFixed(n);
		},
		tradeClose(){
			request('/trades/position/close', 'POST', {
				guid:"001",
				loginId:this.userinfo.Customer.loginId,
				sessionId:this.userinfo.SessionId,
				positionId:JSON.parse(this.msg).id
			}).then(res => {	
				console.log(res.data,222)
				  if(res.data.ResultCD=="I001"){
		             toast("平仓成功");
					
				 }else{
					toast(res.data.ErrorMsg);
				 }
				
			});
		}
	},
	onLoad(options) {
		this.msg = options.msg;
		console.log(JSON.parse(this.msg));
	},
	
	
	
};
</script>
<style lang="scss" scoped>
.nav {
	width: 80%;
	display: flex;
	justify-content: space-between;
	margin: 0 auto;
	padding-top: 40upx;
	.nav-one {
		width: 48%;

		text-align: left;
	}
	.nav-two {
		width: 48%;

		text-align: left;
	}
}
</style>
